/**
 * 
 */

import { createStore, applyMiddleware, combineReducers } from 'redux';
import { AsyncStorage } from 'react-native'
import { persistStore, persistCombineReducers } from 'redux-persist';
// Middleware
import thunk from 'redux-thunk';
import promise from './promise.js'
import track from './track.js'
// reducers
import { auth } from '../reducers/auth.js';
import { bank } from '../reducers/bank.js';

// 添加 Middleware
const createStoreWithMiddleware = applyMiddleware(
  thunk, promise, track
)(createStore);
// 合并 reducers
const reducers = persistCombineReducers(
  { key: 'root', storage: AsyncStorage },
  { auth, bank }
)
var store = null
export const configureStore = (onComplete) => {
  store = createStoreWithMiddleware(reducers)
  persistStore(store, null, () => { onComplete(store) })
}
export const getStore = () => {
  return store
}
